<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 0px
        }

        .colorRed {
            color: red;
        }

        .bqName {
            padding: 2px 4px;
            border-radius: 6px;
            background: #f66;
            cursor: pointer;
        }
    </style>

</head>

<body class="white-bg" style="color:#333;padding:3px;">
<div class="white-bg setRemindPeopleK" style="margin:10px">
    <form action="" class="form-inline" id="add" method="post">
        <table class="table-bordered table text-center">
            <tr class="info">
                <td>网点联络信息<span class="colorRed">(至少填一条)</span></td>
                <td colspan="6"></td>
            </tr>
            <tr class="info">
                <td>联系人姓名<span class="colorRed">*</span></td>
                <td>联系电话<span class="colorRed">*</span></td>
                <td>手机<span class="colorRed">*</span></td>
                <td>传真</td>
                <td>电子邮件</td>
                <td>职务</td>
                <td>
                    <button class="btn btn-success addManInfo">添加</button>
                </td>
            </tr>
            {volist name="data" id="row"}
            <tr>
                <td>{$row.name}</td>
                <td>{$row.phone}</td>
                <td>{$row.mobile}</td>
                <td>{$row.fax}</td>
                <td>{$row.email}</td>
                <td>{$row.job}</td>
                <td>
                    {if $row.isdel==1}
                    <button class="btn btn-success qiyong" data-id="{$row.id}">启用</button>
                    {else}
                    <button class="btn btn-success del" data-id="{$row.id}">删除</button>
                    {/if}
                </td>
            </tr>
            {/volist}

        </table>

        <div class="col-md-12 text-center" style="padding: 10px 0">
            <button class="btn-success btn" id="tijiao">确认并提交</button>
            <button class="btn-warning btn" id="cancelBack">返回</button>
        </div>

    </form>
</div>

<!-- 全局js -->
{include file="Public/footer"}
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>

<script>
    $(document).ready(function () {


        // 添加系统联系人信息
        $(".addManInfo").on("click", function () {
            var str = '<tr><td><input type="text" class="form-control input1" style="width: 100px;min-width: 100px" name="systemContact[name][]"></td><td><input type="text" class="form-control input2" style="width: 50px;min-width: 50px" name="systemContact[phone1][]">-<input type="text" class="form-control input22" style="width: 100px;min-width: 100px" name="systemContact[phone2][]"></td><td><input type="text" class="form-control input21" name="systemContact[mobile][]" style="width: 120px;min-width: 120px"></td><td><input type="text" class="form-control input2" style="width: 50px;min-width: 50px" name="systemContact[fax1][]">-<input type="text" class="form-control input22" style="width: 100px;min-width: 100px" name="systemContact[fax2][]"></td><td><input type="text" class="form-control input21"  name="systemContact[email][]" style="width: 120px;min-width: 120px"></td><td><input type="text" class="form-control input21"  name="systemContact[job][]"></td><td><button class="btn btn-danger delthis">删除</button></td></tr>'
            $(this).closest("table").append(str);

            return false
        })

        $(document).on("click", ".delthis", function () {
            $(this).parent().parent().remove();
            return false
        })

        //删除
        $('.del').on('click',function () {
            var id = $(this).data('id')
            $.post('{:url("deleteContact")}',{id:id},function (data) {
                if (data.success) {
                    swal({
                        title: data.msg,
                        type: "success"
                    }, function () {
                        location.reload()
                    });

                } else
                    swal({
                        title: data.msg,
                        type: "warning"
                    });

            },'json')
            return false
        })

        //启用
        $('.qiyong').on('click',function () {
            var id = $(this).data('id')
            $.post('{:url("qiyongContact")}',{id:id},function (data) {
                if (data.success) {
                    swal({
                        title: data.msg,
                        type: "success"
                    }, function () {
                        location.reload()
                    });

                } else
                    swal({
                        title: data.msg,
                        type: "warning"
                    });

            },'json')
            return false
        })


    })


</script>
<script>
    var cancelBack = document.getElementById('cancelBack')
    cancelBack.onclick = function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }


    //提交
    $('#tijiao').on('click', function () {
        var form = $('#add')
        var serial = form.serialize()

        $.ajax({
            'type': 'post',
            'url': form.attr('action'),
            'data': serial,
            'dataType': 'json',
            'success': function (data) {
                if (data.success) {
                    top.swal({
                        title: data.msg,
                        type: "success"
                    }, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name))
                    });

                } else
                    top.swal({
                        title: data.msg,
                        type: "warning"
                    });
            }
        })
        return false
    })

</script>

</body>

</html>